using Gtk;
using GLib;

namespace Debins {
    public class App : Gtk.Application {

        public App() {
            Object(
                application_id: "com.eminfedar.debins",
                flags: ApplicationFlags.HANDLES_OPEN
            );
        }

        protected override void activate() {
            var window = new MainWindow(this, null);
            window.show_all();
        }

        protected override void open(File[] files, string hint) {
            if( files.length == 1 && files[0].query_exists() ) {
                string[] tagSplit = files[0].get_basename().split(".");
                string tag = tagSplit[tagSplit.length-1];
                 
                if ( tag == "kur" ) {
                    var packageManager = new PackageManager(files[0]);

                    //if (packageManager.isValid) {
                        var window = new MainWindow(this, packageManager);
                        window.show_all();
                    //}
                } else {
                    stderr.printf("Sadece .kur dosyası.\n");
                    Process.exit(1);
                }
            }
        }
    }

    public static int main(string[] args) {
        var app = new App();
        return app.run(args);
    }
}
